package com.ruoyi.backend2.controller;

import com.ruoyi.backend2.interfaces.Role;
import com.ruoyi.backend2.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
public class UserController {
    @Autowired
    private UserService userService;

    @Role(value = Role.GUEST)
    @PostMapping("/api/login")
    public ResponseEntity<String> login(@RequestParam("username") String username, @RequestParam("password") String password) {
        String token = userService.getUser(username, password);
        // 返回token
        return ResponseEntity.ok(token);
    }

    @Role(value = Role.USER)
    @GetMapping("/api/user")
    public ResponseEntity<Void> getUser(@RequestParam String id) {
        return ResponseEntity.ok().build();
    }

    @Role(value = Role.ADMIN)
    @DeleteMapping("/api/user")
    public ResponseEntity<Void> deleteUser(@RequestParam String id) {
        return ResponseEntity.ok().build();
    }
}
